<!--
 * @Author: your name
 * @Date: 2021-11-18 21:50:11
 * @LastEditTime: 2021-11-18 22:04:28
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\斐波那契数列递归.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //递归
        /*function fib(n) {
            if (n < 2) {
                return n
            }
            return fib(n - 1) + fib(n - 2)
        }
        console.log(fib(10));*/

        //循环
        function fib(num) {
            let numarr = [0,1];
            for (let index = 2; index <= num; index++) {
                numarr[index]=numarr[index-1]+numarr[index-2];
            }
            return numarr[num];
        }
        console.log(fib(10));
    </script>
</body>

</html>